//JavaScript代码区域
layui.use(['layer', 'form', 'laydate', 'table'], function() {
	var layer = layui.layer,
		$ = layui.$,
		form = layui.form,
		laydate = layui.laydate,
		table = layui.table;
	//监听提交
	form.on('submit(formDemo)', function(data) {
		table.reload('idTest', {
			where: data.field
		});
		return false;
	});
	//执行一个laydate实例
	laydate.render({
		elem: '#start',
		max: 0
	});
	laydate.render({
		elem: '#end',
		max: 0
	});

	//数据表格实例
	table.render({
		id: 'idTest',
		elem: '#demo',
		url: IP + '/api/teacher_eav/teacherLogin/withMe',
		//		height: 'full-180',
		method: 'get',
		page: false,
		even: true,
		cols: [
			[{
				field: 'tId',
				width: 100,
				title: '老师id',
				sort: true,
				hide: true
			}, {
				field: 'cId',
				width: 100,
				title: '课程id',
				sort: true,
				hide: true
			}, {
				field: 'dName',
				title: '院系',
			}, {
				field: 'tNo',
				title: '老师工号'
			}, {
				field: 'tName',
				title: '老师姓名',
				style: 'text-align:center;'
			}, {
				field: 'cName',
				title: '课程名',
				style: 'text-align:center;'
			}, {
				field: 'scoresT',
				title: '我的评价(分数)',
				style: 'text-align:center;',
				//				sort: true,
				totalRow: true
			}, {
				width: 200,
				title: '操作',
				align: 'center',
				toolbar: '#barDemo'
			}]
		],
		request: {
			pageName: 'page',
			limitName: 'pageSize'
		},
		response: {
			statusName: 'code',
			statusCode: 200,
			msgName: 'message',
			countName: 'count',
			dataName: 'data'
		},
		done: function(res, curr, count) {
			layer.closeAll('loading');
			$('tr:first').css({
				'background-color': '#4BB2FF',
				'color': '#fff',
				'font-size': '80px'
			});

			$("[data-field = 'scoresT']").children().each(function() {
				if($(this).text().length > 0) {
					$(this).parents().next('.layui-table-col-special').children().children('.evaluate').remove()
				} else if($(this).text() == "") {
					$(this).parents().next('.layui-table-col-special').children().children('.details').remove()
					$(this).text(" 未 评 价 ").css("color", 'red');
				}
			});
			refreshTableDict();
		},
		parseData: function(res) { //res 即为原始返回的数据
			return {
				"code": res.code, //解析接口状态
				"message": res.message, //解析提示文本
				"count": res.count, //解析数据长度
				"data": res.data //解析数据列表
			};
		}
	});

	//数据表格监听工具条(查看、编辑、删除按钮)
	table.on('tool(test)', function(obj) {
		var data = obj.data;
		var layEvent = obj.event;
		if(layEvent === 'edit') {
			top.layer.open({
				type: 2,
				title: '综合评价 ( ' + data.cName + '老师：' + data.tName + ' )',
				shadeClose: false,
				shade: 0.8,
				area: ['100%', '100%'],
//					content: 'selectTeacher.html?tId=' + data.tId + '&&cId=' + data.cId + '' //iframe的url
				content: 'admin/teacher/selectTeacher.html?tId=' + data.tId + '&&cId=' + data.cId + '' //iframe的url
				,end: function() {
					table.reload('idTest');
				}
				,cancel: function() {
					//询问框
					top.layer.open({
					  resize:false,
					  skin: 'layui-layer-lan',
					  content: '<h3 style="color:red">暂未评教完成，确定关闭？</h3>'
					  ,btn: ['确定', '取消']
					  ,yes: function(index, layero){
					 	parent.layer.closeAll(); //疯狂模式，关闭所有层
					  }
					  ,btn2: function(index, layero){
					    //按钮【按钮二】的回调
					  }
					});
					return false;
				}
			});
		} else if(layEvent === 'follows') {
			top.layer.open({
				type: 2,
				title: '综合评价详情 ( ' + data.cName + '老师：' + data.tName + ' )',
				shadeClose: false,
				shade: 0.8,
				area: ['100%', '100%'],
//				content: 'detailsTeacher-see.html?tId=' + data.tId + '&&cId=' + data.cId + '' //iframe的url
				content: 'admin/teacher/detailsTeacher-see.html?tId=' + data.tId + '&&cId=' + data.cId + '' //iframe的url
			});
		}
	});

//更新表格字典信息
function refreshTableDict() {
	var table_datas = $('#demo').siblings('.layui-form').children('.layui-table-box')
		.children('.layui-table-body').children('.layui-table').children('tbody').children('tr');

	$.each(table_datas, function(idx, obj) {
		//类别
		var scoreNum = $(this).children("td[data-field='scoreNum']").children('div');
	});
}

});